package cn.ldh.org.service.impl;

import cn.ldh.basic.util.PageList;
import cn.ldh.org.domain.Department;
import cn.ldh.org.mapper.DepartmentMapper;
import cn.ldh.org.query.DepartmentQuery;
import cn.ldh.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper mapper;

    @Override
    public List<Department> loadAll() {
        return mapper.loadAll();
    }

    @Override
    public Department loadById(Long id) {
        return mapper.loadById(id);
    }

    @Transactional
    @Override
    public void save(Department department) {
        mapper.save(department);

    }

    @Transactional
    @Override
    public void delete(Long id) {
        mapper.delete(id);

    }

    @Transactional
    @Override
    public void update(Department department) {
        mapper.update(department);

    }

    @Override
    public PageList<Department> queryPage(DepartmentQuery query) {

        Integer count = mapper.queryCount(query);
        if (count==null || count ==0){
            return new PageList<>();

        }

        List<Department> list = mapper.queryData(query);


        return new PageList<>(count,list);
    }
}
